package com.zj.whichone.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zj.whichone.bean.ReturnInfo;
import com.zj.whichone.bean.User;
import com.zj.whichone.constant.Default;
import com.zj.whichone.constant.ReturnCode;

import cn.hn.java.summer.db.BaseDao;
import cn.hn.java.summer.db.multiple.DataSource1;
import cn.hn.java.summer.mvc.WebContext;
@Service
public class UserService  extends BaseDao<DataSource1>{
	@Autowired
	LoginService loginService;
	public ReturnInfo updatePassword(User param){
		ReturnInfo rinfo = new ReturnInfo();
		User user=WebContext.getSessionCookie(Default.USER_SESSION_KEY,User.class);
		user = loginService.login(user);
		if(!user.getPassword().equals(param.getPassword())){
			rinfo.setCode(ReturnCode.PASSWORD_FAIL);
			rinfo.setMsg("密码错误");
			return rinfo;
		}
		user.setPassword(param.getNewPassword());
		if(this.update("updatePassword",user)<1){
			rinfo.setCode(ReturnCode.PASSWORD_UPDATEFAIL);
			rinfo.setMsg("修改密码失败");
			return rinfo;
		}
		rinfo.setMsg("密码修改成功");
		return rinfo;
	}
}
